layui.use(['form','layarea'], function () {
    var form = layui.form,
        layer = layui.layer
        , layarea = layui.layarea;

    // 登录过期的时候，跳出ifram框架
    if (top.location != self.location) top.location = self.location;

    // 粒子线条背景
    $(document).ready(function(){
        $('.layui-container').particleground({
            dotColor:'#7ec7fd',
            lineColor:'#7ec7fd'
        });
    });

    // 进行登录操作
    form.on('submit(login)', function (data) {
        data = data.field;
        if (data.username == '') {
            layer.msg('用户名不能为空');
            return false;
        }
        if (data.password == '') {
            layer.msg('密码不能为空');
            return false;
        }
        if (data.captcha == '') {
            layer.msg('验证码不能为空');
            return false;
        }
        if (data.password !== data.again_password){
            layer.msg("两次密码不一致");
            return false;
        }
        if (data.pay_password !== data.again_pay_password){
            layer.msg("两次支付密码不一致");
            return false;
        }
        let address = $(".province-selector").val()+$(".city-selector").val()+$(".county-selector").val()
        data.address = address;
        $.ajax({
            type:"post",
            url:"/reg",
            data:data,
            dataType:"json",
            success:function (res){
                if (res.code == 200){
                    layer.msg(res.msg,{
                        icon:1
                    },function (){
                        window.location = "/";
                    })
                }else{
                    layer.msg(res.msg,{
                        icon:2
                    })
                }
            }
        })
        return false;
    });

    form.verify({
        pay_password:[
            /^[0-9]{6,6}$/,"支付密码必须六位"
        ]
    })

    layarea.render({
        elem: '#area-picker'
    })

    form.render();
});